package com.ys.web.sys.notice.task;

import com.ys.utils.base.j2se.StringHandler;
import com.ys.web.sys.notice.service.NoticeService;
import com.ys.web.sys.notice.vo.SystemNoticeVo;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @作者: dhf
 * @名称: 用户系统消息
 * @时间: 2022/9/3 3:25
 * @备注:
 */
@Component
@Slf4j
public class UserSystemNoticeTask implements Job {
    @Autowired
    private NoticeService noticeService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("用户系统消息---------开始");
        Map<String,Object> map = noticeService.getUserSystemNotice();
        if (StringHandler.isNotEmpty(map)) {
            SystemNoticeVo systemNoticeVo = new SystemNoticeVo();
            systemNoticeVo.setTitle(StringHandler.getString(map.get("title")));
            systemNoticeVo.setContent(StringHandler.getString(map.get("notice")));
            systemNoticeVo.setUserId(1L);
            if(StringHandler.getInt(map.get("isAll"))==1)
                systemNoticeVo.setIsAll(false);
            if(StringHandler.getInt(map.get("isAll"))==2)
                systemNoticeVo.setIsAll(true);
            systemNoticeVo.checkParam();
            noticeService.addNotice(systemNoticeVo);
        }else{
            log.info("用户系统消息---------没有发送的消息");
        }
        log.info("用户系统消息---------结束");
    }

}
